<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th>名称：</th>
				<td style="position: relative;">
					<input name="name" class="easyui-validatebox" type="text" data-options="required: true" style="float:left;"/>
				</td>
			</tr>
			<tr>
				<th>权限标识：</th>
				<td>
					<input name="identity" class="easyui-validatebox" data-options="required: true" type="text" />
				</td>
			</tr>
			<tr>
				<th>权限描述：</th>
				<td>
					<input name="description" class="easyui-validatebox" type="text" />
				</td>
			</tr>
			<tr>
				<th>排序：</th>
				<td>
					<input name="sorting" class="easyui-numberbox" type="text" data-options="prompt: '不填写则为默认排序'" />
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id!}">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/manager/system/permit/add", id = "${id!}" ;
	$(function(){
		if(undefined != id && "" != id) {
			form_url = "${ctx}/manager/system/permit/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/manager/system/permit/get/"+id,
				success: function(result) {
					$("#form").form("load", result);
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					$.easyui.loaded();
					if(XMLHttpRequest.status == 403) {
						$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
					} else {
						$.messager.alert("错误", "发生未知错误", "error");
					}
				}
			});
		}
		
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

